home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.cin.gov.au!usenet
- From: rossw@cin.gov.au (Ross Wilson)
- Newsgroups: comp.lang.c
- Subject: Re: goto
- Date: Wed, 27 Mar 1996 01:51:03 GMT
- Organization: Community Information Network
- Message-ID: <4ja6u3$8v5@canb.cin.gov.au>
- References: <Pine.OSF.3.91.960313102715.10701D-100000@io.UWinnipeg.ca>
- NNTP-Posting-Host: chico.cin.gov.au
- X-Newsreader: Forte Free Agent 1.0.82
-
- Bill Simpson <wsimpson@uwinnipeg.ca> wrote:
-
- >There was a goto thread lately, and my problem is to state this algorithm
- >cleanly without gotos (which I think is easy, but my attempts have been
- >failures).
-
- >0. x=0;
- >1. x+=erand(maxmean);
- >2. if (urand2()>rate(x)/maxrate)
- > goto step 1
- >3. if (x<=XMAX)
- > {
- > setdot(x,y,z);
- > goto step 1
- > }
-
- <explanations of erand(), etc, snipped>
-
- One simple translation might be:
-
- x = 0;
- for (;;)
- {
- x += erand(maxmean);
- if (urand2() > rate(x) / maxrate)
- continue;
- if (x <= XMAX)
- {
- setdot(x, y, z);
- continue;
- }
- break;
- }
-
- but it looks kind of clumsy to have a break last thing in the loop.
- A slight remolding gives:
-
- x = 0;
- for (;;)
- {
- x += erand(maxmean);
- if (urand2() > rate(x) / maxrate)
- continue;
- if (x > XMAX)
- break;
- setdot(x, y, z);
- }
-
- which looks a little better.
-
- I don't think there is any really good, universally acceptable answer
- to this sort of thing.
-
- Ross
-
-